package com.lu.manage.modular.system.controller;


import com.lu.manage.core.tips.SuccessTip;
import com.lu.manage.modular.system.model.server.Server;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

/**
 * 服务器监控
 * @Author: ZhangLu
 * @Date: 2019-04-18 16:12
 * @Version 1.0
 */
@RequestMapping("/system/monitor")
@Controller
public class MonitorController {

    private static String PREFIX = "/modular/system/monitor";

    @GetMapping("/server")
    public Object index(){
        return PREFIX + "/server/index.html";
    }

    @GetMapping("/server/data")
    @ResponseBody
    public Object data(){
        return new SuccessTip(Server.serverData());
    }

//    @RequestMapping("/send")
//    @ResponseBody
//    public Object send(String msg){
//        //通过websocket给当前机构发消息
//        try {
//            Map<String, NoticeWebSocket> sessionMap =  NoticeWebSocket.getSessionMap();
//            for(String k : sessionMap.keySet()){
//                NoticeWebSocket v = sessionMap.get(k);
//                Map<String,String> map = new HashMap<>();
//                map.put("title","websocket");
//                map.put("message",msg);
//                v.getSession().getBasicRemote().sendText(JSON.toJSONString(map));
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//        return new SuccessTip();
//
//    }

    public static void main(String[] args) throws Exception {
        FileInputStream fin = new FileInputStream("/Users/zhanglu/Downloads/all_vrdata_2019-7-4.txt");
        InputStreamReader isr = new InputStreamReader(fin);
        BufferedReader br = new BufferedReader(isr);
        String s = "[";
        String temp = "";
        while((temp = br.readLine()) != null){
            s += temp + ",";
        }
        s = s.substring(0, s.lastIndexOf(","));
        s += "]";
        System.out.println(s);
    }

}
